package com.zhdl.modules.logging.web.controller;

import com.zhdl.common.util.WebResult;
import com.zhdl.modules.logging.service.OptRecordService;
import com.zhdl.modules.logging.web.req.OptRecordListRequest;
import com.zhdl.modules.logging.web.resp.OptRecordListResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping(path = "/optRecords", produces = MediaType.APPLICATION_JSON_VALUE)
public class OptRecordController {

    @Resource
    private OptRecordService optRecordService;

    @PostMapping("/get/optRecords/page/data/{pageSize}/{pageNumber}")
    public WebResult<Page<OptRecordListResp>> findAllRecord(@RequestBody @Validated OptRecordListRequest request, @PathVariable int pageNumber, @PathVariable int pageSize){
        Pageable pageable = PageRequest.of(pageNumber, pageSize);
        Page<OptRecordListResp> allRecordPage = optRecordService.findAllRecordPage(request, pageable);
        return WebResult.okResult(allRecordPage);
    }

}
